package com.wzdigit.wms.basic.mapper.core.inventory;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wzdigit.framework.orm.mybatis.MyBatisRepository;
import com.wzdigit.wms.basic.domain.inventory.Goods;
import com.wzdigit.wms.basic.domain.inventory.GoodsHis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@MyBatisRepository
public interface GoodsHisMapper extends BaseMapper<GoodsHis> {

    @Select("<script>" +
            "WITH T AS (\n" +
            "SELECT MAX(T.GOODS_HIS_ID) ID FROM WMS_GOODS_HIS T\n" +
            "WHERE T.GOODS_SN IN \n" +
            "<foreach collection='snList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> \n" +
            "GROUP BY T.GOODS_SN  \n" +
            ")\n" +
            "SELECT W.GOODS_SN,W.PKG_ID,W.OWNER,W.SKU_ID,W.FACTORY,W.VENDOR_ID,W.VEN_LOTNO,W.PRD_LOT,W.PRD_WO,W.PRD_DATE,W.EXPIRE_DATE,W.STOCK_IN_DATE,\n" +
            "       W.VALIDITY_PERIOD,W.DATECODE,W.LOTNO,W.INV_ATTR,W.QA_STATUS,W.SO_NO,W.SO_ITEM,W.SO_TYPE,W.SELL_FLAG,W.PO_NO,W.MFG_PLANT,W.MFG_LINE,W.INSP_NO,W.QTY,\n" +
            "       W.UNIT,W.STATUS,W.LAST_INSP_TIME,W.NEXT_INSP_TIME,W.INSP_COUNT,W.IS_HOLD,W.ACCEPT_BY_CONCESSION,W.GROSS_WEIGHT,W.TARE,W.NET_WEIGHT,\n" +
            "       W.LENGTH,W.WIDTH,W.HEIGHT,W.CUBE,W.PRICE,W.MSL,NVL(W.SOURCE_GOODS_ID, W.GOODS_ID) SOURCE_GOODS_ID,W.IS_ORIGINAL_PACKAGE,W.STRIP_DATE,W.UDF1,W.UDF2,W.UDF3,W.UDF4,W.UDF5,W.COMMENTS,W.CREATE_USER,\n" +
            "       W.CREATE_TIME,W.MODIFY_USER,W.MODIFY_TIME \n" +
            "FROM WMS_GOODS_HIS W\n" +
            " INNER JOIN T ON W.GOODS_HIS_ID = T.ID \n" +
            "</script>")
    List<Goods> selectGoodsByHisSn(@Param("snList") List<String> snList);

    @Select("<script>" +
            "WITH T AS (\n" +
            "SELECT MAX(T.GOODS_HIS_ID) ID FROM WMS_GOODS_HIS T\n" +
            "WHERE T.GOODS_SN IN \n" +
            "<foreach collection='snList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> \n" +
            "GROUP BY T.GOODS_SN  \n" +
            ")\n" +
            "SELECT W.GOODS_SN,W.PKG_ID,W.OWNER,W.SKU_ID,W.FACTORY,W.VENDOR_ID,W.VEN_LOTNO,W.PRD_LOT,W.PRD_WO,W.PRD_DATE,W.EXPIRE_DATE,W.STOCK_IN_DATE,\n" +
            "       W.VALIDITY_PERIOD,W.DATECODE,W.LOTNO,W.INV_ATTR,W.QA_STATUS,W.SO_NO,W.SO_ITEM,W.SO_TYPE,W.SELL_FLAG,W.PO_NO,W.MFG_PLANT,W.MFG_LINE,W.INSP_NO,W.QTY,\n" +
            "       W.UNIT,W.STATUS,W.WHS_ID,W.LAST_INSP_TIME,W.NEXT_INSP_TIME,W.INSP_COUNT,W.IS_HOLD,W.ACCEPT_BY_CONCESSION,W.GROSS_WEIGHT,W.TARE,W.NET_WEIGHT,\n" +
            "       W.LENGTH,W.WIDTH,W.HEIGHT,W.CUBE,W.PRICE,W.MSL,NVL(W.SOURCE_GOODS_ID, W.GOODS_ID) SOURCE_GOODS_ID,W.IS_ORIGINAL_PACKAGE,W.STRIP_DATE,W.UDF1,W.UDF2,W.UDF3,W.UDF4,W.UDF5,W.COMMENTS,W.CREATE_USER,\n" +
            "       W.CREATE_TIME,W.MODIFY_USER,W.MODIFY_TIME \n" +
            "FROM WMS_GOODS_HIS W\n" +
            " INNER JOIN T ON W.GOODS_HIS_ID = T.ID \n" +
            "</script>")
    List<Goods> selectGoodsWithWhsByHisSn(@Param("snList") List<String> snList);
}
